using System;
using System.Collections.Generic;
using System.Text;
using FlatRedBall;
using FlatRedBall.Input;
using FlatRedBall.AI.Pathfinding;
using FlatRedBall.Graphics.Animation;
using FlatRedBall.Graphics.Particle;

using FlatRedBall.Math.Geometry;
using FlatRedBall.Math.Splines;
using BitmapFont = FlatRedBall.Graphics.BitmapFont;
using Cursor = FlatRedBall.Gui.Cursor;
using GuiManager = FlatRedBall.Gui.GuiManager;

#if FRB_XNA || SILVERLIGHT
using Keys = Microsoft.Xna.Framework.Input.Keys;
using Vector3 = Microsoft.Xna.Framework.Vector3;
using Texture2D = Microsoft.Xna.Framework.Graphics.Texture2D;


#endif

namespace Gnome.Entities
{
    public partial class HidingSpot
    {
        private void CustomInitialize()
        {
            CollisionRadius.Radius = 2;
        }
        public void shake()
        {
            //AppleTreeSprite.CurrentChainIndex = 0;
        }
        private void CustomActivity()
        {
            // make the flap animation play only once
            if (AppleTreeSprite.JustCycled)
            {
                AppleTreeSprite.Animate = false;
            }
        }

        private void CustomDestroy()
        {


        }

        public void SetupSprite(Sprite inputsprite)
        {
            Position = inputsprite.Position;
            AppleTreeSprite = inputsprite;
            Z = 1;
            if (inputsprite.Texture.ToString().Contains("appletree"))
            {
                CollisionBox.ScaleX = AppleTreeSprite.ScaleX * 0.2f;
                CollisionBox.ScaleY = AppleTreeSprite.ScaleY / 6;
                CollisionBox.RelativeY = -(AppleTreeSprite.ScaleY - CollisionBox.ScaleY * 3f);
                CollisionRadius.RelativeY = CollisionBox.RelativeY*1.1f;
                CollisionBox.RelativeX = 0.3f;
                CollisionRadius.Radius = CollisionBox.ScaleX*5;
                CollisionRadius.RelativeX = CollisionBox.RelativeX;
                EffectSprite = SpriteManager.AddSprite(@"Content/Screens/LevelOne/images/appletreeeffect.png");
                EffectSprite.Position = AppleTreeSprite.Position;
                EffectSprite.ScaleX = AppleTreeSprite.ScaleX;
                EffectSprite.ScaleY = AppleTreeSprite.ScaleY;
                AppleTreeSprite.AnimationChains.Add(IdleAnimations[0]);
                AppleTreeSprite.AnimationChains.Add(IdleAnimations[1]);
                GlowSprite = SpriteManager.AddSprite(@"Content/Screens/LevelOne/images/appletreeoutline.png");
                GlowSprite.Position = AppleTreeSprite.Position;
                GlowSprite.ScaleX = AppleTreeSprite.ScaleX;
                GlowSprite.ScaleY = AppleTreeSprite.ScaleY;
                EffectGlowSprite = SpriteManager.AddSprite(@"Content/Screens/LevelOne/images/appletreeeffectoutline.png");
                EffectGlowSprite.Position = AppleTreeSprite.Position;
                EffectGlowSprite.ScaleX = AppleTreeSprite.ScaleX;
                EffectGlowSprite.ScaleY = AppleTreeSprite.ScaleY;
                HidingEffectSprite = SpriteManager.AddSprite(@"Content/Screens/LevelOne/images/appletreehidingeffect.png");
                HidingEffectSprite.Position = AppleTreeSprite.Position;
                HidingEffectSprite.ScaleX = AppleTreeSprite.ScaleX;
                HidingEffectSprite.ScaleY = AppleTreeSprite.ScaleY;
            }
            else if (inputsprite.Texture.ToString().Contains("tree"))
            {
                CollisionBox.ScaleX = AppleTreeSprite.ScaleX * 0.75f;
                CollisionBox.ScaleY = AppleTreeSprite.ScaleY/6;
                CollisionBox.RelativeY = -(AppleTreeSprite.ScaleY - CollisionBox.ScaleY*2);
                CollisionRadius.RelativeY = CollisionBox.RelativeY*0.7f;
                CollisionBox.RelativeX = 0.21f;
                CollisionRadius.Radius = CollisionBox.ScaleX * 1.3f;
                CollisionRadius.RelativeX = CollisionBox.RelativeX;
                EffectSprite = SpriteManager.AddSprite(@"Content/Screens/LevelOne/images/treeeffect.png");
                EffectSprite.Position = AppleTreeSprite.Position;
                EffectSprite.ScaleX = AppleTreeSprite.ScaleX;
                EffectSprite.ScaleY = AppleTreeSprite.ScaleY;
                GlowSprite = SpriteManager.AddSprite(@"Content/Screens/LevelOne/images/treeoutline.png");
                GlowSprite.Position = AppleTreeSprite.Position;
                GlowSprite.ScaleX = AppleTreeSprite.ScaleX;
                GlowSprite.ScaleY = AppleTreeSprite.ScaleY;
                EffectGlowSprite = SpriteManager.AddSprite(@"Content/Screens/LevelOne/images/treeeffectoutline.png");
                EffectGlowSprite.Position = AppleTreeSprite.Position;
                EffectGlowSprite.ScaleX = AppleTreeSprite.ScaleX;
                EffectGlowSprite.ScaleY = AppleTreeSprite.ScaleY;
                HidingEffectSprite = SpriteManager.AddSprite(@"Content/Screens/LevelOne/images/treehidingeffect.png");
                HidingEffectSprite.Position = AppleTreeSprite.Position;
                HidingEffectSprite.ScaleX = AppleTreeSprite.ScaleX;
                HidingEffectSprite.ScaleY = AppleTreeSprite.ScaleY;
                AnimationChain idle = (IdleAnimations[2]);
                AnimationChain hiding = (IdleAnimations[3]);
                // Weird hack is needed for some reason, only happens in Trees and bushes
                AnimationFrame newfirst = idle.LastFrame;
                idle.Remove(newfirst);
                idle.Insert(0, newfirst);
                AppleTreeSprite.AnimationChains.Add(idle);
                newfirst = hiding.LastFrame;
                hiding.Remove(newfirst);
                hiding.Insert(0, newfirst);
                AppleTreeSprite.AnimationChains.Add(hiding);
            }
            else
            {
                AppleTreeSprite.ScaleX = AppleTreeSprite.ScaleX * 1.25f;
                AppleTreeSprite.ScaleY = AppleTreeSprite.ScaleY * 1.25f;
                CollisionBox.ScaleX = AppleTreeSprite.ScaleX;
                CollisionBox.ScaleY = AppleTreeSprite.ScaleY/2;
                CollisionBox.RelativeY = -(CollisionBox.ScaleY / 2);
                CollisionBox.RelativeX = -0.4f;
                CollisionRadius.Radius = CollisionBox.ScaleX * 1.1f;
                CollisionRadius.RelativeX = CollisionBox.RelativeX;
                EffectSprite = SpriteManager.AddSprite(@"Content/Screens/LevelOne/images/busheseffect.png");
                EffectSprite.Position = AppleTreeSprite.Position;
                EffectSprite.ScaleX = AppleTreeSprite.ScaleX;
                EffectSprite.ScaleY = AppleTreeSprite.ScaleY;
                GlowSprite = SpriteManager.AddSprite(@"Content/Screens/LevelOne/images/bushesoutline.png");
                GlowSprite.Position = AppleTreeSprite.Position;
                GlowSprite.ScaleX = AppleTreeSprite.ScaleX;
                GlowSprite.ScaleY = AppleTreeSprite.ScaleY;
                EffectGlowSprite = SpriteManager.AddSprite(@"Content/Screens/LevelOne/images/busheseffectoutline.png");
                EffectGlowSprite.Position = AppleTreeSprite.Position;
                EffectGlowSprite.ScaleX = AppleTreeSprite.ScaleX;
                EffectGlowSprite.ScaleY = AppleTreeSprite.ScaleY;
                HidingEffectSprite = SpriteManager.AddSprite(@"Content/Screens/LevelOne/images/busheshidingeffect.png");
                HidingEffectSprite.Position = AppleTreeSprite.Position;
                HidingEffectSprite.ScaleX = AppleTreeSprite.ScaleX;
                HidingEffectSprite.ScaleY = AppleTreeSprite.ScaleY;
                AnimationChain idle = (IdleAnimations[4]);
                AnimationChain hiding = (IdleAnimations[5]);
                // Weird hack is needed for some reason, only happens in Trees and bushes
                AnimationFrame newfirst = idle.LastFrame;
                idle.Remove(newfirst);
                idle.Insert(0, newfirst);
                AppleTreeSprite.AnimationChains.Add(idle);
                newfirst = hiding.LastFrame;
                hiding.Remove(newfirst);
                hiding.Insert(0, newfirst);
                AppleTreeSprite.AnimationChains.Add(hiding);
            }
            GlowSprite.Visible = false;
            EffectGlowSprite.Visible = false;
            HidingEffectSprite.Visible = false;
        }

        private static void CustomLoadStaticContent(string contentManagerName)
        {


        }
    }
}
